const common = require('../api/config.js')
const host = common.host
const commonParams = {
  cid: 'admins',
  uid: 'admins'
}
export function upload(option) {
  wx.uploadFile({
    url: host + '/MtmlAPI/Upload',
    filePath: option.data.tempFilePath,
    name: 'image',
    success: res => {
      if (option.success) {
        option.success(JSON.parse(res.data))
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(JSON.parse(res.data))
      }
    }
  })
}

export function onLogin(option) {
  let data = Object.assign({}, option.data)
  let url = host + '/MtmlAPI/OnLogin'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}
// 1.用户微信登录注册
export function checkIsBind(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/CMSAPI/CheckIsBind'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function hospitalList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/HospitalList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function featureService(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/FeatureService'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getInfoPicture(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/GetInfoPicture'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function hospitalDetails(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/HospitalDetails'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function doctorList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/DoctorList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function checkClass(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/CheckClass'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function sucessCaseList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/SucessCaseList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getALLProduct(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetALLProduct'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function addReceiveAddress(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/AddReceiveAddress'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getReceiveAddress(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetReceiveAddress'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function setDefaultAddress(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/SetDefaultAddress'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function deleteReceiveAddress(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/DeleteReceiveAddress'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function updateReceiveAddress(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/UpdateReceiveAddress'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getReceiveDetails(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetReceiveDetails'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getCateProducts(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetCateProducts'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getProductDetail(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetProductDetail'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getProductCate(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetProductCate'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function httpGetStr(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/httpGetStr'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function shopingCart(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/ShopingCart'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function itemShoppingCart(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/ItemShoppingCart'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function seeItemShoppingCart(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/SeeItemShoppingCart'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function seeShopingCart(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/SeeShopingCart'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getWXappPay(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetWXappPay'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      console.log(res)
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function moblie(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/moblie'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function wXappUpdateOrder(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/WXappUpdateOrder'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function setProPay(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/SetProPay'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function projPayUpdateOrder(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/ProjPayUpdateOrder'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getAllOrder(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'NPLAPI/GetAllOrder'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function itemOrder(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/ItemOrder'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function daySign(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/DaySign'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

// 获取用户资料
export function GetUserCRMInfo(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/GetUserCRMInfo'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

// 用户个人资料修改
export function UserSettingsUpdate(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/UserSettingsUpdate'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function sMSphone(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/SMSphone'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function phoneEdit(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/PhoneEdit'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function sucessCaseDetails(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/SucessCaseDetails'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function doctorDetails(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/DoctorDetails'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getDeliveryFee(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/GetDeliveryFee'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function activeCategory(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/ActiveCategory'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function activeDetail(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/ActiveDetail'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function bindPartner(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/BindPartner?'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function promoteSendIntegral(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/PromoteSendIntegral?'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getSpecialEventsDetail(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + 'MtmlAPI/GetSpecialEventsDetail?'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function mainInList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/CMSAPI/MainInList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function categoryByLevel(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/CMSAPI/CategoryByLevel'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function detail(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/CMSAPI/detail'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function approve(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/Approve'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function commentList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/CommentList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function commentCreate(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/CommentCreate'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function ownList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/OwnList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function commentDelete(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/MtmlAPI/CommentDelete'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

/******积分商城******/
export function getSalesIntegralProducts(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/YYLAPI/GetSalesIntegralProducts'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getIntegralProductDetail(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/YYLAPI/GetIntegralProductDetail'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getIntegral(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/CMSAPI/GetIntegral'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function insertIntegralOrder(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/YYLAPI/InsertIntegralOrder'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
} 

export function useMoney(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/mtmlAPI/UseMoney'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function integralOrderList(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/NPLAPI/IntegralOrderList'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getVIPInfor(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/mtmlapi/GetVIPInfor'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function gussYouLike(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/mtmlapi/GussYouLike'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function getVIPTypes(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/mtmlapi/GetVIPTypes'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
} 

export function getWxQrCode(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/mtmlapi/GetWxQrCode'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
} 

export function buyVIP(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/nplapi/BuyVIP'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function VIPPayUpdateOrder(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/nplapi/VIPPayUpdateOrder'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}

export function addCard(option) {
  let data = Object.assign({}, commonParams, option.data)
  let url = host + '/NPLAPI/AddCard'
  wx.request({
    url: url,
    data: data,
    success: res => {
      if (option.success) {
        option.success(res.data)
      }
    },
    fail: res => {
      if (option.fail) {
        option.fail(res.data)
      }
    }
  })
}